//
//  RxTableTest.swift
//  CooperSwift_Example
//
//  Created by 计海峰 on 2021/4/29.
//  Copyright © 2021 CocoaPods. All rights reserved.
//

import Foundation
import UIKit
import RxSwift
import CooperSwift

class RxTableTestVC: UIViewController {
    
    let disposeBag = DisposeBag()
    
    private let tv: UITableView = {
        var tv = UITableView.init()
        tv.backgroundColor = UIColor.white
        return tv
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.addSubview(tv)
        
        tv.snp.makeConstraints { (make) in
            make.edges.equalTo(view).inset(UIEdgeInsets.zero)
        }
        
        tv.register(UINib(nibName: "RxTableTestCell", bundle: nil), forCellReuseIdentifier: "RxTableTestCell")
        
        let list = ["Objective-C", "Swift", "RXSwift"]
        let obser = Observable.from(optional: list)
        
        obser.bind(to:
            tv.rx.items(cellIdentifier: "RxTableTestCell", cellType: RxTableTestCell.self))
            { (row, text, cell) in
                cell.titleLB?.text = text
            }
            .disposed(by: disposeBag)


        tv.rx.itemSelected.bind { indexPath in
            debugPrint(indexPath)
        }.disposed(by: disposeBag)
        
    }
}
